<?php

/**
 * This is the model class for table "leaseviolations".
 *
 * The followings are the available columns in table 'leaseviolations':
 * @property integer $id
 * @property integer $idTenant
 * @property integer $idOccupancy
 * @property string $LeaseViolationShortDescription
 * @property string $LeaseViolationDateOfOccurance
 *
 * The followings are the available model relations:
 * @property Occupancy $idOccupancy0
 * @property Tenant $idTenant0
 */
class Leaseviolations extends CActiveRecord
{
	public $AddressOne,$UnitNumber,$userName,$tfirstName,$tlastName;
	/**
	 * Returns the static model of the specified AR class.
	 * @return Leaseviolations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'leaseviolations';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idTenant, idOccupancy', 'numerical', 'integerOnly'=>true),
			array('LeaseViolationShortDescription', 'length', 'max'=>35),
			array('LeaseViolationDateOfOccurance', 'safe'),
			array('LeaseViolationDateOfOccurance,LeaseViolationShortDescription', 'required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('tfirstName,tlastName,AddressOne, UnitNumber, userName, id, idTenant, idOccupancy, LeaseViolationShortDescription, LeaseViolationDateOfOccurance', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idOccupancy0' => array(self::BELONGS_TO, 'Occupancy', 'idOccupancy'),
			'idTenant0' => array(self::BELONGS_TO, 'Tenant', 'idTenant'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idTenant' => 'Id Tenant',
			'idOccupancy' => 'Id Occupancy',
			'LeaseViolationShortDescription' => 'Short Description',
			'LeaseViolationDateOfOccurance' => 'Date Of Occurance',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$sort = new CSort();
		 $sort->attributes = array(

		   'userName'=>array(
		      'asc'=>$this->userName,
		      'desc'=>$this->userName,
				 ),
		
			'LeaseViolationShortDescription' => array(
               'asc'=>'LeaseViolationShortDescription',
               'desc'=>'LeaseViolationShortDescription desc',
             ),
				 
		   'AddressOne'=>array(
		      'asc'=>$this->AddressOne,
		      'desc'=>$this->AddressOne,
				 ),
				 
			'LeaseViolationDateOfOccurance' => array(
               'asc'=>'LeaseViolationDateOfOccurance',
               'desc'=>'LeaseViolationDateOfOccurance desc',
             ),		 
		
		   'UnitNumber'=>array(
		      'asc'=>$this->UnitNumber,
		      'desc'=>$this->UnitNumber,
		 		),
		 		
		 
		 );
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idTenant',$this->idTenant);
		$criteria->compare('idOccupancy',$this->idOccupancy);
		$criteria->compare('LeaseViolationShortDescription',$this->LeaseViolationShortDescription,true);
		$criteria->compare('LeaseViolationDateOfOccurance',$this->LeaseViolationDateOfOccurance,true);
		$criteria->compare('userName', $this->userName, true);
		$criteria->compare('AddressOne', $this->AddressOne, true);
		$criteria->compare('UnitNumber', $this->UnitNumber, true);
		$criteria->compare('FirstName', $this->tfirstName, true);
		$criteria->compare('LastName', $this->tlastName, true);
		
		$criteria->with=array('idOccupancy0','idOccupancy0.idRentalUnit0','idOccupancy0.idRentalProperty0','idTenant0','idTenant0.iduser0');
		$criteria->together=true;
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'sort'=>$sort,
		));
	}
}